
function layerPopClose(){
	$(".layerPop").slideUp(function(){
		$(".dimm").fadeOut();
	})
}
function layerPopShow(id){
	if($(".dimm").length == 0){
		$("body").append("<div class='dimm' style='display:none' >")
	}
	var layerEl = $(id);
	var top =  (document.body.parentNode.clientHeight  /2-layerEl.height()/2)+ ($("html").scrollTop() +$("body").scrollTop());
	layerEl.css({top:top})
	$(".dimm").fadeIn(function(){
		$(id).slideDown()	
	})
}

function layerPopSetting(mass){
	if($(".dimm").length == 0){
		$("body").append("<div class='dimm' style='display:none' >")
	}
	var dimm = $(".dimm");
	var dimm2 = false;
	if(mass)
	for (var i=0; i<mass.length ; i++ )
	{
		var layerArr = mass[i];
		var btn = $(layerArr.btn);
		if(btn.length ==0) continue;
		btn.each(function(j){
			btn[j].layerArr = layerArr;
		}).live("click",function(e){
			var layerArr = this.layerArr;
			var This = this;
			if(!layerArr.addLayer){
				$(".layerPop").hide()
			}else{
				$(layerArr.layer).css({zIndex:110});
				$("body").append("<div class='dimm addLayer'>");
				dimm2 = $(".dimm.addLayer");
			}
			if(layerArr.openChkeck){
				if(layerArr.openChkeck()){
					openLayer(This.layerArr);
					e.preventDefault(); 
				}
			}else{
				openLayer(This.layerArr);
					e.preventDefault(); 
			}
		})
	}

	$(".layerPop a.close").each(function(){
		this.layerEl = $(this.parentNode.parentNode.parentNode);
		this.parent = $(this.parentNode);
		this.parentNode.close = $(this);
	}).click(function(){
		if(dimm2)dimm2.remove();
		var layerEl = this.layerEl;
		layerEl.slideUp(function(){
			var showChk = true;
			$(".layerPop").each(function(){
				if(this.style.display != "none"){
					showChk = false;
				}
			});
			if(showChk) closeLayer(this);
		});
		return false;
	});

	function openLayer(layerArr){
		dimm.fadeIn(function(){
			var layerEl = $(layerArr.layer);
			var top =  (document.body.parentNode.clientHeight  /2-layerEl.height()/2)+ ($("html").scrollTop() +$("body").scrollTop());
			layerEl.css({top:top})
			layerEl[0].callback = layerArr.closeCallback;
			layerEl.slideDown(function(){
				if(layerArr.openCallback) layerArr.openCallback();	
			});
		});
	}

	function closeLayer(layerEl){
		if(dimm2) dimm2.remove();
		dimm.fadeOut(function(){
			if(layerEl.callback) layerEl.callback();	
		});
	}

	return {
		hide : function(layerArr){
			if(!layerArr){
				$(".layerPop").each(function(){
					if(this.style.display != "none"){
						this.close.click();
					}
				});
			}else{
				
			}
		},
		open : function(layerArr){
			$(".layerPop").hide()
			openLayer(layerArr);
		}
	}
}
function layerPopSetting_mini(mass){
	if(mass)
	for (var i=0; i<mass.length ; i++ )
	{
		var layerArr = mass[i];
		var btn = $(layerArr.btn);
		if(btn.length ==0) continue;
		btn.each(function(j){
			btn[j].layerArr = layerArr;
		}).click(function(){
			var layerArr = this.layerArr;
			var This = this;
			
			if($(this.layerArr.layer)[0].style.display != "none") return false;

			if(!layerArr.addLayer){
				$(".layerPop_min").hide()
			}else{
				$(layerArr.layer).css({zIndex:110});
			}
			if(layerArr.openChkeck){
				if(layerArr.openChkeck()){
					openLayer_min(This.layerArr);
					return false;
				}
			}else{
				openLayer_min(This.layerArr);
				return false;
			}
		})
	}

	$(".layerPop_min a.close").each(function(){
		this.layerEl = $(this.parentNode);
		this.parent = $(this.parentNode);
		this.parentNode.close = $(this);
	}).click(function(){
		var layerEl = this.layerEl;
		layerEl.slideUp(300,function(){
			var showChk = true;
			$(".layerPop_min").each(function(){
				if(this.style.display != "none"){
					showChk = false;
				}
			});
			if(showChk) closeLayer(this);
		});
		return false;
	});

	function openLayer_min(layerArr){
			var layerEl = $(layerArr.layer);
			//var top =  (document.body.parentNode.clientHeight  /2-layerEl.height()/2)+ ($("html").scrollTop() +$("body").scrollTop());
			//layerEl.css({top:top})
			layerEl[0].callback = layerArr.closeCallback;
			layerEl.slideDown(function(){
				if(layerArr.openCallback) layerArr.openCallback();	
			});
	}

	function closeLayer(layerEl){
		if(layerEl.callback) layerEl.callback();	
	}

	return {
		hide : function(layerArr){
			if(!layerArr){
				$(".layerPop_min").each(function(){
					if(this.style.display != "none"){
						this.close.click();
					}
				});
			}else{
				
			}
		},
		open : function(layerArr){
			$(".layerPop").hide()
			openLayer_min(layerArr);
		}
	}
}



// .layerPop_min 레이어 열고 닫기
function miniLayerClose(id){
	$(id).slideUp(300);
}

function miniLayerShow(id){
	$(id).slideDown();
}
// .layerPop_min 레이어 열고 닫기